from bs4 import BeautifulSoup
import requests
import time as tm
import hashlib
import re


def get_str_sha(str):
    sha = hashlib.sha1(str)
    return sha.hexdigest()
user_id = "201603445"
passwd = "201603445"

Header = {
        "User-Agent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
       # "Cookie" : "semester.id=48; JSESSIONID=94C5B1089F6A9634033AC62808407116.node132; adc-ck-jwxt_pools=IEALAKAK; GSESSIONID=94C5B1089F6A9634033AC62808407116.node132",
        }
LoginUrl = "http://221.233.24.23/eams/login.action"
Url = "http://221.233.24.23/eams/stdDetail.action"
s = requests.Session()
req = s.get(LoginUrl)
html = req.text

res = re.search("CryptoJS.SHA1\(\'(.*)\' ",html)
opasswd = res.group(1)
passwd = get_str_sha((opasswd+passwd).encode("utf-8"))
print(passwd)
tm.sleep(2)
Data = {
    "username" : user_id,
    "password" : passwd,
    "encodedPassword:" : "",
    "session_locale" : "zh_CN",
}
req = s.post(LoginUrl,data=Data)
print(req.text)
